package com.joysuch.wwyt.monitoringcenter.bean;

import cn.zlg.common.util.CollectionUtils;
import com.google.common.collect.Lists;
import com.joysuch.wwyt.monitoringcenter.enums.AlarmTypes;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @Author ZhangDong
 * @Date 2020/9/14 15:32
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LocateAlarmRecord {

    @ApiModelProperty("报警ID")
    private String uuid;
    @ApiModelProperty("报警时间")
    private Long time;
    @ApiModelProperty("报警类型")
    private String type;
    @ApiModelProperty("位置")
    private String areaName;
    @ApiModelProperty("报警人员名字")
    private String name;
    @ApiModelProperty("SN号")
    private String mac;
    @ApiModelProperty("处理时间")
    private Long handleTime;
    @ApiModelProperty("处理信息")
    private String handleRemark;
    @ApiModelProperty("报警类型名称")
    private String typeName;
    @ApiModelProperty("报警信息")
    private String alarmInfo;

    @ApiModelProperty("报警人员id")
    private String userId;
    @ApiModelProperty("区域报警，围栏点位集合")
    private List<PointBean> points;

    /**
     * 一键报警：【人员名称】触发了【一键报警】
     * 越界报警：【人员名称】在【区域名称】触发了【越界报警】
     * 滞留报警：【人员名称】在【区域名称】触发了【滞留报警】
     * 静止报警：【人员名称】在【区域名称】触发了【静止报警】
     * 超员报警：【区域名称】发生了【超员报警】
     * 缺员报警：【区域名称】发生了【缺员报警】
     */
    public LocateAlarmRecord(LinkedHashMap record) {
        this.uuid = (String) record.get("uuid");
        this.time = (Long) record.get("time");
        this.type = (String) record.get("type");
        this.areaName = (String) record.get("areaName");
        this.name = (String) record.get("name");
        this.mac = (String) record.get("mac");
        this.handleTime = (Long) record.get("handleTime");
        this.handleRemark = (String) record.get("handleRemark");
        this.typeName = AlarmTypes.getName(type);
        this.userId = (String) record.get("userId");
        if (AlarmTypes.ONE_KEY_ALARM.getType().equals(this.type)) {
            this.alarmInfo = String.format("【%s】触发了【%s】", this.name, this.typeName);
        } else if (AlarmTypes.OVER_BOUNDARY_ALARM.getType().equals(this.type)) {
            this.alarmInfo = String.format("【%s】在【%s】触发了【%s】", this.name, this.areaName, this.typeName);
        } else if (AlarmTypes.LACK_NUM.getType().equals(this.type)) {
            this.alarmInfo = String.format("【%s】发生了【%s】", this.areaName, this.typeName);
        } else if (AlarmTypes.OVER_NUM.getType().equals(this.type)) {
            this.alarmInfo = String.format("【%s】发生了【%s】", this.areaName, this.typeName);
        } else if (AlarmTypes.STAY_ALARM.getType().equals(this.type)) {
            this.alarmInfo = String.format("【%s】在【%s】触发了【%s】", this.name, this.areaName, this.typeName);
        } else if (AlarmTypes.STILL_ALARM.getType().equals(this.type)) {
            this.alarmInfo = String.format("【%s】在【%s】触发了【%s】", this.name, this.areaName, this.typeName);
        }

        if (AlarmTypes.OVER_NUM.getType().equals(this.type) || AlarmTypes.LACK_NUM.getType().equals(this.type)) {
            List<LinkedHashMap> list = (List<LinkedHashMap>) record.get("points");
            List<PointBean> points = Lists.newArrayList();
            if (!CollectionUtils.isEmpty(list)) {
                for (LinkedHashMap map : list) {
                    Integer x = (Integer) map.get("x");
                    Integer y = (Integer) map.get("y");
                    points.add(new PointBean(x, y));
                }
            }
            this.points = points;
        }
    }

}
